//
//  CAnAlgRltExerData.m
//  CareRing
//
//  Created by  on 2024/10/12.
//  测量期间实时数据

#import "CAnAlgRltExerData.h"

@implementation CAnAlgRltExerData
- (instancetype)initWithData:(NSData *)data
{
    if (self = [super init]) {
        if (data.length < 20) {
            return self;
        }
        
        uint8_t *dataBytes = (uint8_t *)[data bytes];
        _cmdByte = dataBytes[1];
        // 四字节时间戳
//        uint32_t timeStamp = *((uint32_t *)(dataBytes + 2));
//        _timeStamp = timeStamp;
        
        _steps = *((uint16_t *)(dataBytes + 2)) & 0XFFFF;
        
        _distance = (*((uint16_t *)(dataBytes + 4)) & 0XFFFF) / 10.0f;
        
        _speed = dataBytes[6];
        _cadence = dataBytes[7]; // 步频
        _wholeEnergyCnsmptn =  *((uint16_t *)(dataBytes + 8)) & 0XFFFF;
        _activityEnergyCnsmptn = *((uint16_t *)(dataBytes + 10)) & 0XFFFF;
        _met = (*((uint16_t *)(dataBytes + 12)) & 0XFFFF) /10.0f;
        _exerType = dataBytes[14];
        _heartRate = dataBytes[15];
        
        uint8_t caco = dataBytes[16];
        if (caco!= 0XFF) {
            _caco = @(caco/100.0f);
        }
        
    }
    return self;
}
@end
